// export default usePersonHouseData;
import { reactive } from "vue";
import liaoning from "@/utils/liaoning.json";
const getImageUrl = (name: string) => {
  return new URL(`../../assets/img/HouseRentPro/${name}.png`, import.meta.url).href;
};
const usePersonHouseData = (): any => {
  // 数据部分
  const personHouseData = reactive<any>({
    personHouseCommodityData: {},
    // 租赁人员年龄分布  男女比例
    priceIndexData: {},
    priceIndexData1: {},
    // 国有土地使用权收入额走势
    transactionData: {},
    // 住宅地价指数走势
    priceTrendData: {},
    // 土地成交情况统计
    residentialTrendData: {},
    residentialTrendDataR: {},
    // 土地成交走势
    residentialRentPriceIndexData: {},
    // 住宅地价及同比增长率走势
    andPriceData: {},
    // 异常情况走势
    housingVacancyRateData: {},
    // 中间地图
    personHouseMiddleData: {},
    cityName: "",
    dialogVisible: false,
    componentName: "",
    componentParams: {},
    mjName: "全部面积",
    hxName: "全部户型",
    cityCode: localStorage.getItem("cityCode"),
    cityCode1: localStorage.getItem("cityCode"),
    cityName1: "",
    cityCode2: localStorage.getItem("cityCode"),
    cityName2: "",
    cityCode3: localStorage.getItem("cityCode"),
    cityName3: "",
    cityCode4: localStorage.getItem("cityCode"),
    cityName4: "",
    cityCode5: localStorage.getItem("cityCode"),
    cityName5: "",
    cityCode6: localStorage.getItem("cityCode"),
    cityName6: "",
    cityCode7: localStorage.getItem("cityCode"),
    cityName7: "",
    cityCode8: localStorage.getItem("cityCode"),
    cityName8: "",
    data1: [],
    data2: [],
    data4: [],
    data5: [],
    data6: [],
    data7: [],
    data8: [],
    titleList: [
      { name: "出租房源总量", num: 0, imgURL: getImageUrl("title1") },
      { name: "网签合同总量", num: 0, imgURL: getImageUrl("title2") },
      { name: "出租人员总量", num: 0, imgURL: getImageUrl("title3") },
    ],
    getLeasePersonSourceRankData: [],
    getRegionListData: [],
    getBaseDropDownData: [],
    seriesData: [],
  });
  let arr = liaoning.features.find((item: any) => item.properties.adcode == localStorage.getItem("cityCode"));
  const cityName = arr?.properties.name || "辽宁省";
  personHouseData.cityName =
    personHouseData.cityName1 =
    personHouseData.cityName2 =
    personHouseData.cityName3 =
    personHouseData.cityName4 =
    personHouseData.cityName5 =
    personHouseData.cityName6 =
    personHouseData.cityName7 =
    personHouseData.cityName8 =
      cityName;

  // 获取当前时间
  let date = new Date();
  let year = date.getFullYear();
  let month = date.getMonth() + 1;

  // 计算近三个月的时间范围
  let startTime = year + "-" + (month - 2 < 10 ? "0" + (month - 2) : month - 2);
  let endTime = year + "-" + (month < 10 ? "0" + month : month);

  // 设置默认时间范围
  if (personHouseData) {
    personHouseData.data1 = [startTime, endTime];
    personHouseData.data2 = year + "-" + (month - 2 < 10 ? "0" + month : month);
    personHouseData.data4 = year + "-" + (month - 2 < 10 ? "0" + month : month);
    personHouseData.data5 = year + "-" + (month - 2 < 10 ? "0" + month : month);
    personHouseData.data7 = [startTime, endTime];
    personHouseData.data8 = year + "-" + (month - 2 < 10 ? "0" + month : month);
  }
  return personHouseData;
};
export default usePersonHouseData;
